# -*- coding: utf-8 -*-

import time
from wbhttp import HttpClient
from logger import logger
from weibo import Weibo


class WeiboComment(Weibo):
    def send_comment(self, wid, text):

        url = "https://m.weibo.cn/api/comments/create"

        headers = {
            'Referer': 'https://m.weibo.cn/compose/comment?id=%s' % wid,
            'Origin': 'https://m.weibo.cn',
        }

        data = {
            "id": wid,
            "mid": wid,
            "content": text,
            "st": self.get_st(),
        }

        logger.info('https://m.weibo.cn/status/%s' % wid)

        resp = HttpClient.post(url, data, headers)
        if resp.status_code == 200 and resp.json()['ok'] == 1:
            logger.info(u'发表评论成功')
        else:
            logger.info(u'发表评论失败:%s' % resp.json()['msg'])
